from xpinyin import Pinyin


def test():
    p = Pinyin()
    # 'shang-hai'，默认分隔符为"-"
    p.get_pinyin(u"上海")

    # 显示声调 'shàng-hǎi'
    p.get_pinyin(u"上海", show_tone_marks=True)

    # 设置分隔符 'shang hai'
    p.get_pinyin(u"上海", ' ')

    # 只显示声母 'S'
    p.get_initial(u"上")

    # 显示多字声母，并设置分隔符'SH'
    p.get_initials(u"上海", u'')

    # 只显示声母小写 's'
    p.get_initials(u"上", '').swapcase()


def getPy(n):
    p = Pinyin()
    n1 = n[0]
    n2 = n[1:]
    return p.get_initials(n2, '').swapcase() + p.get_pinyin(n1, '')


def getPyFirst(n):
    p = Pinyin()
    n1 = n[0]
    n2 = n[1:]
    return p.get_initials(n2, '').swapcase()

# 邮箱命名规则
# 张雷
# 1.zlei@cfss.net.cn
# 2.zhanglei@cfss.net.cn
# 3.zhangl@cfss.net.cn
# 4.zl@cfss.net.cn
# 黄志永
# 1.hzyong@cfss.net.cn
# 2.hzhiyong@cfss.net.cn
# 3.huangzhiyong@cfss.net.cn
# 4.huangzhiy@cfss.net.cn
# 5.huangzy@cfss.net.cn
# 6.hzy@cfss.net.cn


def first(name):
    p = Pinyin()
    for_initial_str = ""
    with_finals_str = ""
    # 只要声母
    for_initial = name[0:-1]
    # 带韵母
    with_finals = name[-1]
    for_initial_str = p.get_initials(for_initial, '').swapcase()
    with_finals_str = p.get_pinyin(with_finals, '')
    return for_initial_str + with_finals_str


def second(name):
    p = Pinyin()
    for_initial_str = ""
    with_finals_str = ""
    if len(name) > 2:
        # 只要声母
        for_initial = name[0:-2]
        for_initial_str = p.get_initials(for_initial, '').swapcase()
    # 带韵母
    with_finals = name[-2:]
    with_finals_str = p.get_pinyin(with_finals, '')
    return for_initial_str + with_finals_str


def third(name):
    p = Pinyin()
    for_initial_str = ""
    with_finals_str = ""
    if len(name) > 3:
        # 只要声母
        for_initial = name[0:-3]
        for_initial_str = p.get_initials(for_initial, '').swapcase()
        # 带韵母
        with_finals = name[-3:]
        with_finals_str = p.get_pinyin(with_finals, '')
    elif len(name) == 3:
        # 带韵母
        with_finals = name[-3:]
        with_finals_str = p.get_pinyin(with_finals, '')
    else:
        # 只要声母
        for_initial = name[1]
        for_initial_str = p.get_initials(for_initial, '').swapcase()
        # 带韵母
        with_finals = name[0]
        with_finals_str = p.get_pinyin(with_finals, '')
    return for_initial_str + with_finals_str


def fourth(name):
    p = Pinyin()
    for_initial_str = ""
    with_finals_str = ""
    if len(name) > 2:
        # 带韵母
        with_finals = name[0:-2]
        with_finals_str = p.get_pinyin(with_finals, '')
    # 只要声母
    for_initial = name[-2:]
    for_initial_str = p.get_initials(for_initial, '').swapcase()
    return with_finals_str + for_initial_str


if __name__ == '__main__':
    name = "黄志"
    print(first(name))
    print(second(name))
    print(third(name))
    print(fourth(name))